import { defHttp } from "/@/utils/http/axios"
import { Modal } from "ant-design-vue"

enum Api {
  list = "/pay-service/mgr/payIfDefine/page",
  save = "/pay-service/mgr/payIfDefine/save",
  listPayIfDefine = "/pay-service/mgr/payIfDefine/list",
  getByIfCode = "/pay-service/mgr/payIfDefine/getByIfCode",
  edit = "/pay-service/mgr/payIfDefine/update",
  delete = "/pay-service/mgr/payIfDefine/delete",

  deleteBatch = "/pay-service/mchInfo/deleteBatch",
}

/**
 * 查询列表
 * @param params
 */
export const listPayIfDefine = (params) => {
  return defHttp.get({ url: Api.list, params })
}

/**
 * 查询列表
 * @param params
 */
export const listAllPayIfDefine = (params) => {
  return defHttp.get({ url: Api.listPayIfDefine, params })
}

/**
 * 获取相信信息
 * @param params
 */
export const getByIfCode = (params) => {
  return defHttp.get({ url: Api.getByIfCode, params })
}

/**
 * 删除
 * @param params
 */
export const deletePayIfDefine = (params, handleSuccess) => {
  return defHttp.delete({ url: Api.delete, data: params }, { joinParamsToUrl: true }).then(() => {
    handleSuccess()
  })
}

/**
 * 批量删除
 * @param params
 */
export const batchDeletePayIfDefine = (params, handleSuccess) => {
  Modal.confirm({
    title: "确认删除",
    content: "是否删除选中数据",
    okText: "确认",
    cancelText: "取消",
    onOk: () => {
      return defHttp.delete({ url: Api.deleteBatch, data: params }, { joinParamsToUrl: true }).then(() => {
        handleSuccess()
      })
    },
  })
}

/**
 * 保存或者更新角色
 * @param params
 */
export const saveOrUpdatePayIfDefine = (params, isUpdate) => {
  const url = isUpdate ? Api.edit : Api.save
  return defHttp.post({ url: url, params })
}
